<%@ page language="java" contentType="text/html; charset=utf-8"	pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
 
 <%
	 String signcert= request.getSession().getAttribute("pemsigncert").toString();
	 String enccert= request.getSession().getAttribute("pemenccert").toString();
	 String enckeypair= request.getSession().getAttribute("encpair").toString();
	 String checkid = request.getSession().getAttribute("certId").toString();
	 String reqno = request.getSession().getAttribute("reqno").toString();
	 String userPin = request.getSession().getAttribute("userPin").toString();
	// System.out.println("userPin install:"+userPin);
%>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<link href="./jsp/resource/css/netca2.css" rel="stylesheet" type="text/css">
		<script type="text/javascript" src="<%=basePath%>dwr/util.js"></script>
		<script type="text/javascript" src="<%=basePath%>dwr/engine.js"></script>
		<script type="text/javascript" src="<%=basePath%>dwr/interface/UserServiceImpl.js"></script>
		<script type="text/javascript" src="<%=basePath%>js/jquery.js"></script>

		<script type="text/javascript">
		
		function install(enccert,signcert,enckeypair,checkid,pwd){
			DWREngine.setAsync(false);
			var obj;
				
			try{
				var canameVal="广东省电子商务认证中心";
				
				obj = new ActiveXObject("NetcaBpmsClientCom.PKI");
				if(obj.IsInstalled(canameVal)){
					obj.SetCA(canameVal);
					if(obj.KeyCount>1){
							alert("只能插入1个key");
							return false;
					}
					
					if(pwd != null && pwd != "")
					{
						obj.VerifyPIN(pwd);
					}
					
					//不为空更换密钥
					if(enckeypair!=null&&enckeypair!=""){
						obj.InstallCertAndPrivKey(enccert,signcert,enckeypair);
					}else{
						obj.InstallCert(enccert,signcert);
					}
			 
					//这里更改状态
					var isInstall = UserServiceImpl.updateInstall(1,checkid,callback);
		
				}
			}catch(e){
				alert(e.message);
				return false;
			}
		}
	
		function callback(){
			alert("安装成功！");
		}
	</script>
	
	<title>证书制作</title>
	</head>
	<body onload="install('<%=enccert%>','<%=signcert%>','<%=enckeypair%>','<%=checkid%>','<%=userPin%>')">
	受理号：<input tpye="text" id="req" readonly value="<%=reqno%>">
	</body>
</html>